
using System;
using System.Collections;
using System.Web.UI.WebControls;

namespace Com.Phyfun.Business
{
    #region Tag

    /// <summary>
    /// Tag object for NHibernate mapped table 'Tag'.
    /// </summary>
    public class Tag : BizObject
    {
        #region Member Variables

        protected int _id;
        protected string _tagName;
        protected bool _flagDeleted;
        protected DateTime _logDateTime;
        protected IList _tagGames;
        protected static String _sortExpression = "Id";
        protected static SortDirection _sortDirection = SortDirection.Ascending;

        #endregion

        #region Constructors

        public Tag() { }

        public Tag(int id) { if (id != 0)ObjectBroker.Load(this, id); }

        public Tag(string tagName, bool flagDeleted, DateTime logDateTime)
        {
            this._tagName = tagName;
            this._flagDeleted = flagDeleted;
            this._logDateTime = logDateTime;
        }

        #endregion

        #region Public Properties

        public virtual int Id
        {
            get { return _id; }
            set { _id = value; }
        }

        public virtual string TagName
        {
            get { return _tagName; }
            set
            {
                if (value != null && value.Length > 100)
                    throw new ArgumentOutOfRangeException("Invalid value for TagName", value, value.ToString());
                _tagName = value;
            }
        }

        public virtual bool FlagDeleted
        {
            get { return _flagDeleted; }
            set { _flagDeleted = value; }
        }

        public virtual DateTime LogDateTime
        {
            get { return _logDateTime; }
            set { _logDateTime = value; }
        }

        public virtual IList TagGames
        {
            get
            {
                if (_tagGames == null)
                {
                    _tagGames = new ArrayList();
                }
                return _tagGames;
            }
            set { _tagGames = value; }
        }

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
        #endregion

        #region IComparable Methods
        public virtual int CompareTo(object obj)
        {
            if (!(obj is Tag))
                throw new InvalidCastException("This object is not of type Tag");

            int relativeValue;
            switch (SortExpression)
            {
                case "Id":
                    relativeValue = this.Id.CompareTo(((Tag)obj).Id);
                    break;
                case "TagName":
                    relativeValue = (this.TagName != null) ? this.TagName.CompareTo(((Tag)obj).TagName) : -1;
                    break;
                case "FlagDeleted":
                    relativeValue = (this.FlagDeleted != null) ? this.FlagDeleted.CompareTo(((Tag)obj).FlagDeleted) : -1;
                    break;
                case "LogDateTime":
                    relativeValue = (this.LogDateTime != null) ? this.LogDateTime.CompareTo(((Tag)obj).LogDateTime) : -1;
                    break;
                default:
                    goto case "Id";
            }
            if (Tag.SortDirection == SortDirection.Ascending)
                relativeValue *= -1;
            return relativeValue;
        }
        #endregion
    }

    #endregion
}
